package com.teacold.tfactivity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.teacold.customdemo.R;

import java.util.ArrayList;

import androidx.recyclerview.widget.RecyclerView;

public class SwitchAdapter extends RecyclerView.Adapter<SwitchAdapter.SwitchViewHolder> {
    private ArrayList<String> mData;
    private Context mContext;
    private ItemClickCallback mItemClickCallback;

    public void setmItemClickCallback(ItemClickCallback mItemClickCallback) {
        this.mItemClickCallback = mItemClickCallback;
    }

    public interface ItemClickCallback{
        void itemClick(View view, int position);
        void itemLongClick(View view, int position);
    }

    public SwitchAdapter(ArrayList<String> mData, Context mContext) {
        this.mData = mData;
        this.mContext = mContext;
    }

    @Override
    public SwitchViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.tf_switch_item, null);
        return new SwitchViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final SwitchViewHolder holder, final int position) {
        holder.switch_image.setImageResource(R.mipmap.add_admin);
//        holder.switch_signin.setImageResource(R.mipmap.add_admin);
        holder.switch_nickname.setText(mData.get(position));
        holder.switch_layout.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if(mItemClickCallback!=null){
                    mItemClickCallback.itemLongClick(holder.itemView,position);
                }
                return true;
            }
        });
        holder.switch_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mItemClickCallback!=null){
                    mItemClickCallback.itemClick(holder.itemView,position);
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    public class SwitchViewHolder extends RecyclerView.ViewHolder {
        ImageView switch_image, switch_signin;
        TextView switch_nickname;
        FrameLayout switch_layout;

        public SwitchViewHolder(View itemView) {
            super(itemView);
            switch_layout=itemView.findViewById(R.id.switch_layout);
            switch_image = itemView.findViewById(R.id.switch_image);
            switch_signin = itemView.findViewById(R.id.switch_signin);
            switch_nickname = itemView.findViewById(R.id.switch_nickname);
        }
    }




}
